/***
 *
 * @type {number[]}
 * 改变原数组 push pop shift unshift splice sort reverse
 * 不改变原数组，需要一个新的返回值 slice concat
 */
let a = [1, 2, 3, 4]
console.log(a)

// 改变原数组

a.push(5)
console.log(a)

a.pop()
console.log(a)

a.shift()
console.log(a)

a.unshift(1)
console.log(a)

a.reverse()
console.log(a)

a.reverse()
a.splice(0, 2)
console.log(a)

console.log("================")

// 不改变原数组, 返回一个新的数组
let b = [1, 2, 3, 4]
let c = [5, 6, 7, 8]
let d = b.join('|')
console.log(b)

let e = b.concat(c)
console.log(e)

// arr.slice(start_index, upto_index)
let f = b.slice(0, 2)
console.log(f)

console.log(b.sort())

const sortDesc = (a,b) => {return b -a}
const sortAsc = (a,b) => {return a -b}
console.log(b.sort(sortDesc))
console.log(b.sort(sortAsc))

let g = ['a','b','c','d','e','f']
g.splice(4,2,'g') // a b c d g
console.log(g)

console.log("================")
